﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using YKhoa_Lib.BLL;

namespace ToaThuoc_PAK.Handler
{
    /// <summary>
    /// Summary description for XML_LoadChiTietDichVu
    /// </summary>
    public class XML_LoadChiTietDichVu : IHttpHandler
    {
        DichVu DichVu = null;
        NhomDichVu NhomDichVu = null;
        List<DichVu> lst = null;
        List<NhomDichVu> lstNhom = null;
        public void ProcessRequest(HttpContext context)
        {
            string typeLoad = Factory.emptyNull(context.Request.QueryString["typeLoad"]);
            string MaKhoa = Factory.emptyNull(context.Request.QueryString["MaKhoa"]);
            string xmlReturn = "<Root> \n";
            NhomDichVu = new YKhoa_Lib.BLL.NhomDichVu();
            DichVu = new DichVu();
            DichVu.MaKhoa = MaKhoa;
            switch(typeLoad)
            {
                case "CTDVu":
                    string MaNhom = Factory.emptyNull(context.Request.QueryString["MaNhom"]);
                    DichVu.MaNhom = MaNhom;
                    lst = DichVu.LoadChiTietDichVu();
                    if (lst.Count > 0)
                    {
                        foreach (DichVu item in lst)
                        {
                            xmlReturn += "<DichVu MaDV='" + item.MaDV + "' TenDichVu='" + item.TenDV + "' DonGia='"+ item.DonGia +"'></DichVu>";
                        }
                    }
                    break;
                case "CTNhom":
                    lstNhom = NhomDichVu.LoadChiTietNhomDichVu(MaKhoa);
                    if (lstNhom.Count > 0)
                    {
                        foreach (NhomDichVu item in lstNhom)
                        {
                            xmlReturn += "<NhomDichVu MaNhom='" + item.MaNhom + "' TenNhom='" + item.TenNhom + "'></NhomDichVu>";
                        }
                    }
                    break;
            }            
            
            context.Response.ContentType = "text/xml";
            xmlReturn += "</Root>";
            context.Response.Write(xmlReturn);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}